<?php
include('config.php');

echo "<table width='100%' cellspacing='0'>";
$results = mysql_query("SELECT * FROM devices ORDER BY device_name ASC");
while ($row = mysql_fetch_array($results)) {
	$device_id = $row['device_id'];
	$hostname = $row['device_name'];
	$serial = $row['device_serial'];
	$model = $row['device_type'];
	$ip = $row['device_ip'];

	echo "<tr><td>$model</td><td>$serial</td><td>$hostname</td><td>$ip</td><td><input id='$device_id' type='button' value='Delete' onClick='deleteDevice(\"$device_id\");' /></td></tr>";
}

echo "</table>";
?>

<script type="text/javascript">

function deleteDevice(device_id) {
	alert("Delete: " + device_id);

        var url='pages/query.php?';
        url=url+'device_id='+device_id;
        url=url+'&cmd=deleteDevice';
        
        //Send the data to the query.php script to update the DB
        var myRequest = new Request({
                url: url, 
                onSuccess: function(response) {
                                //Disable the button if it is successful
                                document.getElementById(device_id).disabled=true;
                        } 
        }).send();
}

</script>
